package com.alageek.study.controller;

import com.alageek.study.entity.Book;
import com.alageek.study.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/bookOps")
    public void bookOps(){
        Book b1 = new Book(null, "西厢记", "王实甫");
        int i = bookService.addBook(b1);
        System.out.println("addBook >>> " + i);
        Book b2 = new Book(1, "朝花夕拾", "鲁迅");
        int updateBook = bookService.updateBook(b2);
        System.out.println("updateBook >>> " + updateBook);
        Book b3 = bookService.getBookById(1);
        System.out.println("getBookById >>> " + b3);
        int delete = bookService.deleteBookById(2);
        System.out.println("deleteBookById >>> " + delete);
        List<Book> allBooks = bookService.getAllBook();
        System.out.println("getAllBooks >>> " + allBooks);
    }

}
